/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.uct.controller  
 */
package com.apache.uct.common;

import javax.servlet.http.HttpServletRequest;

import com.apache.action.RestfullSupport;
import com.apache.api.entity.BaseEntity;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultMsg;
import com.apache.database.constant.Validator;
import com.apache.uct.common.entity.User;

/**
 * description:  Action父类
 * @author dwusoft 创建时间：2015-3-25  
 * @Copyright(c)2014:北京--软件技术有限公司
 * @param <T>
 */
public abstract class BaseRestFullAction<T extends BaseEntity> extends RestfullSupport<T> {

	protected User getSessionUser(HttpServletRequest request) {
		LoginUser loginUser = PBOSSOTools.getLoginUser(request);
		if (!Validator.isEmpty(loginUser)) {
			return loginUser.getUser();
		}
		return null;
	}

	protected String getSysFlag(HttpServletRequest request) {
		return Validator.getDefaultStr(String.valueOf(request.getSession().getAttribute("sysUser")), "0");
	}

	protected ResultMsg getResultMsg(HttpServletRequest request, String msg) {
		request.getSession().setAttribute("formToken", request.getAttribute("formToken"));
		ResultMsg rmsg = new ResultMsg("F", msg);
		return rmsg;
	}

	/**
	 * description:  日志生成调用方法
	 * @param request
	 */
	protected ParamsVo<T> getParamsVo(HttpServletRequest request) {
		ParamsVo<T> params = new ParamsVo<T>();
		params.setParams("logIp", getUserIp(request));
		params.setLogClassName(getGenType().trim());
		User user = getSessionUser(request);
		if (null == user)
			return params;
		params.setUserEname(user.getUserEname());
		params.setUserId(user.getUserId());
		return params;
	}

}
